import 'package:app_info/info/appsflyer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:smartloan_mdc/extension/extension.dart';
import 'package:smartloan_mdc/pages/widgets/app_btn.dart';
import 'package:smartloan_mdc/res/string.dart';

import '../../utils/animate/animate.dart';

class VersionDialog extends Dialog {
  VersionDialog({
    this.force = false,
    this.onTap
  });

  bool force;
  Function? onTap;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Stack(
        clipBehavior: Clip.none,
        children: [
          Container(
              width: 300.w,
              // height: 280.h,
              margin: EdgeInsets.only(bottom: force ? 0 : 50.h),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(12),
                  color: Colors.white
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  "version_dialog_top".appImg(width: 300.w, fit: BoxFit.fitWidth),
                  Container(
                    padding: EdgeInsets.symmetric(
                        horizontal: 20.w,
                        vertical: 20.h
                    ),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.start,
                      // crossAxisAlignment: CrossAxisAlignment.s,
                      children: [
                        AppStr.vTitle.sText(fontSize: 20, fontWeight: FontWeight.bold),
                        10.h.hSizedBox(),
                        AppStr.vContent.sText(),
                        20.h.hSizedBox(),
                        AppBtn(
                          content: 'Confirmar',
                          backgroundColor: Color(0xFF4B41A6),
                          onTap: () {
                            AppsFlyer().logEvent('updateConfirm_yes');
                            onTap?.call();
                          },
                        ),
                        10.h.hSizedBox(),
                      ],
                    ),
                  ),
                ],
              )
          ),
          Positioned(
            bottom: 0,
            left: 0,
            right: 0,
            child: force ? SizedBox() : GestureDetector(
              onTap: (){
                AppsFlyer().logEvent('updateConfirm_no');
                Get.back();
              },
              child: Center(
                child: Icon(Icons.cancel_outlined, color: Colors.white, size: 40.r),
              ),
            )
          )
        ],
      ),
    );
  }

  Widget btn(Text content, { Color? color, Function? onPress }) {
    return GestureDetector(
      onTap: () {
        onPress?.call();
      },
      child: Container(
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: color ?? Color(0xFF1846C3),
          borderRadius: BorderRadius.circular(45),
        ),
        child: content,
      ),
    );
  }

  Future show(BuildContext context) async {
    await showAnimDialog(context, VersionDialog(force: force, onTap: onTap));
  }

}